package dev.ece.core.controller;

/**
 * @author 潜行的青衣
 * @see
 */
public abstract class Command {

	private boolean canExecute;
	
	public boolean canExecute() {
		return this.canExecute;
	}
	
	public abstract void onExecute();
	
	public void execute() {
		if(this.canExecute()) {
			this.onExecute();
		}
	}
	
	public abstract void onKeyPress();
	
	public abstract void onKeyRelease();

	public void setCanExecute(boolean canExec) {
		boolean isExec = this.canExecute;
		this.canExecute = canExec;
		if(this.canExecute && !isExec) {
			this.onKeyPress();
		} else if(isExec && !this.canExecute) {
			this.onKeyRelease();
		}
	}
	
}
